package servlet;

import constant.ExamConstant;
import service.RegRecordService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/pay")
public class PayServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
            throws ServletException, IOException {
        try {
            // 获取挂号记录ID
            String recordId = request.getParameter("recordId");
            
            // 更新支付状态
            RegRecordService.updatePaymentStatus(Integer.parseInt(recordId), new Date());
            
            // 重定向回患者主页
            response.sendRedirect("./query?success=payment_success");
            
        } catch (Exception e) {
            e.printStackTrace();
            response.sendRedirect("./query?error=payment_failed");
        }
    }
}